<?php
session_start();
if (empty($_SESSION['user'])) {
    header('location:dl.php');
    exit();
}
header('Content-Type:text/html; charset=UTF-8');
ob_start();

@$yaccount = $_POST['yaccount'];
@$ypassword = $_POST['ypassword'];
@$xaccount = $_POST['xaccount'];
@$xpassword = $_POST['xpassword'];
@$xpassword1 = $_POST['xpassword1'];
$pdo = new PDO('mysql:dbname=dcxt;charset=utf8', 'root');
?>
<html>
<head>
<title>Bootstrap 模板</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
	charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="web/css/bootstrap.min.css" rel="stylesheet">
<script src="web/js/jquery-1.11.1.min.js"></script>
<script src="web/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
		<script src="js/html5shiv.js"></script>
		<script src="js/respond.min.js"></script>
		<![endif]-->
</head>
<body>
	<?php include 'dh.php'; ?>
	<div class="container">
		<div class="col-xs-2">
			<a href="dcxt.php" class="btn btn-default btn-block">返回首页</a>
		</div>
		<div class="col-xs-4">
		<?php
$s = $pdo->prepare('select * from username');
$s->execute();
$data = $s->fetchAll(PDO::FETCH_NAMED);
if ($yaccount != null && $ypassword != null && $xaccount != null && $xpassword != null && $xpassword1 != null) {
    foreach ($data as $value) {
        if ($yaccount == $value['name']) {
            break;
        }
    }
    if ($yaccount != $value['name']) {
        ?>
				<div class="alert alert-danger alert-dismissible ">
				<button type="button" class="close" data-dismiss="alert">
					<span>&times;</span>
				</button>
				用户名错误
			</div>
            <?php
    } elseif ($ypassword == $value['password']) {
        if ($xpassword == $xpassword1) {
            $s1 = $pdo->prepare('update username set name=:xaccount,password=:xpassword where name=:yaccount');
            $isok = $s1->execute(array(
                'xaccount' => $xaccount,
                'xpassword' => $xpassword,
                'yaccount' => $yaccount
            ));
            if ($isok) {
            	header('location: xxxgcg.php');
            } else {

                header('location: xxxgsb.php');
            }
        } else {
            ?>
            	<div class="alert alert-danger alert-dismissible ">
				<button type="button" class="close" data-dismiss="alert">
					<span>&times;</span>
				</button>
				两次密码不一致
			</div>
            <?php
        }
    } else {
        ?>
				<div class="alert alert-danger alert-dismissible ">
				<button type="button" class="close" data-dismiss="alert">
					<span>&times;</span>
				</button>
				密码错误
			</div>
        <?php
    }
}
?>
			<div class="panel panel-primary">
				<div class="panel-heading">
					<div class="panel-lilte">
						<span class="glyphicon glyphicon-edit">
							<b>修改登录信息</b>
						</span>
					</div>
				</div>
				<div class="panel-body"></div>
				<form class="form-horizontal" method="post" action="#">
					<div class="form-group">
						<label class="control-label col-xs-4">原登录名:</label>
						<div class="col-xs-7">
							<input class="form-control" required="required"
								placeholder="原登录名" name="yaccount" />
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-xs-4">原密码:</label>
						<div class="col-xs-7">
							<input class="form-control" required="required" placeholder="原密码"
								name="ypassword" />
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-xs-4">新登录名:</label>
						<div class="col-xs-7">
							<input class="form-control" required="required"
								placeholder="新登录名" name="xaccount" />
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-xs-4">新密码:</label>
						<div class="col-xs-7">
							<input class="form-control" required="required" placeholder="新密码"
								name="xpassword" />
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-xs-4">确认密码:</label>
						<div class="col-xs-7">
							<input class="form-control" required="required"
								placeholder="确认密码" name="xpassword1" />
						</div>
					</div>
					<div class="form-group">
						<button class="btn btn-primary col-xs-3  col-xs-offset-4"
							type="submit">修改</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>

